﻿


function listtag(obj) {
    var temp = "";
    var datas = eval(obj);
   for (var i = 0; i < datas.length; i++) {
       temp = temp + "<a href='/design/tag/" + datas[i].id + "/1.aspx'>"+ datas[i].name + "</a>";

    };
    return temp;
}
PageClick = function (pageIndex, total, spanInterval, page) {

    $.ajax({
        url: "/tools/website.ashx",
        data: { "PageIndex": pageIndex, "color": color, "tag": tag, "name": name },
        type: "get",
        dataType: "json",
        success: function (data) {
            var intPageIndex = parseInt(pageIndex);

            //索引从1开始
            //将当前页索引转为int类型

            if (page != 0) {
                //alert(page);
                //获取显示数据的表格
                var table = $("#content");

                //清楚表格中内容
                $("#content").html("");

                //向表格中添加内容
                for (var i = 0; i < data.list.length; i++) {

                    var pstate = data.list[i].state == 1 ? "当前锁定状态，可以购买" : "当前解锁状态";
                    var pstateclass = data.list[i].state == 1 ? "lock" : "unlock";
                    table.append($('<li class="list_site"><div class="website"><a href="design_show.aspx?id=' + data.list[i].id
                             + '"><img src=' + data.list[i].img + ' ></a></div><div class="info"><a href="design_show.aspx?id=' + data.list[i].id
                             + '"><span class="' + pstateclass + '"></span><p>' + pstate + '</p></a></div> <div class="name"><a href="design_show.aspx?id=' + data.list[i].id + '">' + data.list[i].name
                            + '</a></div><div class="state"><a class="' + pstateclass + '" title="' + pstate + '">' + pstate + '</a></div><div class="tag">标签: ' + listtag(data.list[i].tags) + '</div></li>').hover(function () {
                                $(".info", this).stop().animate({ left: '0px' }, { queue: false, duration: 300 });
                            }, function () {
                                $(".info", this).stop().animate({ left: '-225px' }, { queue: false, duration: 300 });
                            }));

                } //for
            }
            //alert(table.html());
            //创建分页
            //将总记录数结果 得到 总页码数
            total = data.pagecount;
            var count =12;
            var pageS = data.pagecount;
            if (pageS % count == 0) pageS = pageS / count;
            else pageS = parseInt(total / count) + 1;
            var $pager = $("#pager");

            //清楚分页div中的内容
            $("#pager span").remove();
            $("#pager a").remove();



            //设置分页的格式  这里可以根据需求完成自己想要的结果
            var interval = parseInt(spanInterval); //设置间隔
            var start = Math.max(1, intPageIndex - interval); //设置起始页
            var end = Math.min(intPageIndex + interval, pageS)//设置末页

            if (intPageIndex < interval + 1) {
                end = (2 * interval + 1) > pageS ? pageS : (2 * interval + 1);
            }

            if ((intPageIndex + interval) > pageS) {
                start = (pageS - 2 * interval) < 1 ? 1 : (pageS - 2 * interval);

            }


            //生成页码

            for (var j = start; j < end + 1; j++) {
                if (j == intPageIndex) {
                    var spanSelectd = $("<span class='emm-page emm-current corner'>" + j + "</span>");
                    $pager.append(spanSelectd);
                } //if 
                else {
                    var a = $("<a href='javascript:void(0)' class='emm-page corner'  rel='noindex, follow'>" + j + "</a>").click(function () {
                        PageClick($(this).text(), total, spanInterval, 1);
                        return false;
                    });
                    $pager.append(a);
                } //else
            } //for

 //上一页
            if (intPageIndex == pageS) {

                //                $pager.append("<span class='disabled'>下一页</span>");

            }
            else {

                var next = $("<a href='javascript:void(0)' next='" + (intPageIndex + 1) + "' class='button'  rel='noindex, follow'>下一页</a>").click(function () {
                    PageClick($(this).attr("next"), total, spanInterval, 1);
                    return false;
                });
                $pager.append(next);
            }
            //添加上一页
            if (intPageIndex == 1) {
                //$pager.append("<span class='disabled'>上一页</span>");
            }
            else {
                var pre = $("<a href='javascript:void(0)' pre='" + (intPageIndex - 1) + "' class='button'  rel='noindex, follow'>上一页</a>").click(function () {
                    PageClick($(this).attr('pre'), total, spanInterval);
                    return false;
                });
                $pager.append(pre);
            }
           



        } //sucess

    }); //ajax

}     

  //function


        $(function () {

            color = "";
            tag = "";
            name = "";
            PageClick(1, 20, 8, 0);
            systag = $("#systemtag");
            systag.html("");

            ($).ajax({
                url: "/tools/tags.ashx?action=list",
                type: "post",
                dataType: "json",
                success: function (data) {

                    for (var i = 0; i < data.length; i++) {
                        var spantag = $("<span></span>");
                        var temp = $('<a href="javascript:void(0)"  rel="' + data[i].id + '">' + data[i].name + '</a>').click(function () {
                            addtags(this);
                        });

                        spantag.append(temp);
                        systag.append(spantag);
 systag.append("  ");
                    }

                }
            })
            $(".menucolor span").click(function () {

                color = $(this).attr("rel");
                tag = "";
                name = "";
                PageClick(1, 20,8, 1);
            });
        });
        function addtags(obj) {
            color = "";
            tag = $(obj).attr("rel");
            name = "";
            PageClick(1, 20,8, 1);
        }
       
        function search() {
            color = "";
            tag = "";
            if ($("#text").val() != ""&&$("#text").val() != "请输入关键字") {
                name = $("#text").val();
PageClick(1, 20, 8, 1);
            }
            else {
                alert("关键字不能为空");
            }
            
        }


